package com.sxt.business.service.impl;

import java.io.Serializable;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sxt.business.domain.Provider;
import com.sxt.business.mapper.ProviderMapper;
import com.sxt.business.service.IProviderService;
import com.sxt.business.vo.ProviderVO;
import com.sxt.system.constast.Constast;
import com.sxt.system.utils.DataGridView;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 俊哥
 * @since 2019-11-15
 */
@Service
public class ProviderServiceImpl extends ServiceImpl<ProviderMapper, Provider> implements IProviderService {

	@Autowired
	private ProviderMapper providerMapper;
	
	@Override
	public Provider getById(Serializable id) {
		return super.getById(id);
	}

	@Override
	public boolean removeById(Serializable id) {
		return super.removeById(id);
	}

	@Override
	public boolean updateById(Provider entity) {
		return super.updateById(entity);
	}

	@Override
	public DataGridView loadAllProvider(ProviderVO providerVO) {
		IPage<Provider> page = new Page<>(providerVO.getPage(),providerVO.getLimit());
		QueryWrapper<Provider> qw = new QueryWrapper<Provider>();
		qw.like(StringUtils.isNotBlank(providerVO.getProvidername()), "providername", providerVO.getProvidername());
		qw.like(StringUtils.isNotBlank(providerVO.getTelephone()), "telephone", providerVO.getTelephone());
		qw.like(StringUtils.isNotBlank(providerVO.getConnectionperson()), "connectionperson", providerVO.getConnectionperson());
		this.providerMapper.selectPage(page, qw);
		return new DataGridView(page.getTotal(),page.getRecords());
	}

	@Override
	public Provider addProvider(Provider provider) {
		this.getBaseMapper().insert(provider);
		return provider;
	}

	@Override
	public Provider updateProvider(Provider provider) {
		this.getBaseMapper().updateById(provider);
		return provider;
	}

	@Override
	public DataGridView loadAllAvailableProvider() {
		QueryWrapper<Provider> qw = new QueryWrapper<Provider>();
		qw.eq("available", Constast.AVAILABLE_TRUE);
		return new DataGridView(this.getBaseMapper().selectList(qw));
	}
}
